import QtQuick
import QtQuick.Controls.Basic

Button {
    id: control
    text: qsTr("MycustomButton")



    property color colorDefault: "#55aaff"
    property color colorMouseOver: "#ffffff"
    property color colorPressed1: "#cccccc"

    //下面背景有两种绑定方式，建议采用第二种
     //1.不建议采用这种方式，这种方式也能起作用但是没法实时预览
    property var dynamicColor1: if(control.down){
                                   control.down?colorPressed:colorDefault}
                               else{
                                   control.hovered?colorMouseOver:colorDefault
                               }
    //2.建议绑定到QtObject,设计器里可以实时预览到
    QtObject{
        id:internal

        property var dynamicColor: if(control.down){
                                       control.down?colorPressed:colorDefault}
                                   else{
                                       control.hovered?colorMouseOver:colorDefault
                                   }
    }
    background: Rectangle {
        implicitWidth: 100
        implicitHeight: 40
        opacity: enabled ? 1 : 0.3
        //color: dynamicColor1
        color: internal.dynamicColor
        border.width:0
        radius: 20
    }
    contentItem: Text {
        text: control.text
        font: control.font
        opacity: enabled ? 1.0 : 0.3
        color: control.down ? "#2c313c" : "#21be2b"
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        elide: Text.ElideRight
    }


}
